<?php
namespace Worker\Controller;

use Think\Controller;

class BaseController extends Controller
{
    const PSIZE = 20;
    const CPAGE = 1;

    public function __construct()
    {
    }

    /**
     * 判断用户是否存在
     * @param $tab
     * @param $user_id
     * @return bool|mixed
     */
    public function checkUser($tab, $user_id)
    {
        $user = M($tab)->where(['id' => $user_id])->find();
        if ($user) {
            return $user;
        } else {
            return false;
        }
    }

    /**
     * 订单表订单状态描述
     * 0=>未下单 1=>待审核 2=>审核未通过 3=>审核通过 4=>上画待验收 5=>下画待验收 6=>订单完成
     * 1=>待领物料 2=>师傅到店 3=>上画进行中 4=>上画待验收 5=>上画验收成功 6=>下画师傅到店 7=>下画进行中 8=>下画待验收 9=>下画验收完成 10=>已完成
     * @return array
     */
    public function statusMsg()
    {
        return [
            '待接单',
            '待领物料', 
            '待到店施工', 
            '上画进行中',
            '上画待验收', 
            '上画验收成功', 
            '下画进行中',
            '下画待验收', 
            '已完成'
        ];
    }

    /**
     * 统一列表分页数据
     * @param $tab
     * @param array $where
     * @param int $page_size
     * @param int $current_page
     * @param string $field
     * @param string $order
     * @return mixed
     */
    public function getList($tab, $where = [], $page_size = SELF::PSIZE, $current_page = SELF::CPAGE, $field = '*', $order = 'id desc')
    {
        $model = M($tab);
        $list = $model
            ->where($where)
            ->order($order)
            ->join('left join wk_store as s on wk_order.store_id=s.id')
            ->page("$current_page,$page_size")
            ->field('wk_order.*,s.store_name,s.address')
            ->select();
        //var_dump($model->getLastSql());die;
        return $list;
    }

    /**
     * 检测用户登陆信息是否正常
     * @param $tab
     * @param $mobile
     * @param $password
     * @return bool|mixed
     */
    public function chenkLogin($tab, $mobile, $password)
    {
        $userInfo = M($tab)->where(['mobile' => $mobile, 'password' => $password])->find();
        if ($userInfo) {
            return $userInfo;
        } else {
            return false;
        }
    }

    /**
     * 返回对应角色的表明
     * @return array
     */
    public function getRoleTab()
    {
        return [
            1 => 'audit',
            2 => 'store',
            3 => 'worker'
        ];
    }
}